class StorefrontsController < ApplicationController
  
  def index
    params[:key_word] = "%#{params[:key_words]}%"
    @storefronts = Dept::Storefront.where('name like :key_word or address like :key_word or link_man like :key_word or link_phone like :key_word ',params).order('created_at asc')
  end
  
  def new 
    @storefront = Dept::Storefront.new
  end
  
  def create
    @storefront = Dept::Storefront.new(params[:dept_storefront])
    if @storefront.save
      redirect_to :action => :index
    else
      render :new
    end
  end
  
  def edit
    @storefront = Dept::Storefront.find(params[:id])
  end
  
  def update
    @storefront = Dept::Storefront.find(params[:id])
    if @storefront.update_attributes(params[:dept_storefront])
      redirect_to :action => :index
    else
      render :edit
    end
  end
  
  def hide
    @storefront = Dept::Storefront.find(params[:id])
    @storefront.hidden!
    redirect_to :action => :index
  end

  def visible
    @storefront = Dept::Storefront.find(params[:id])
    @storefront.visible!
    redirect_to :action => :index
  end
end
